package com.jeecg.p3.commonluckymoney.web.back;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jeecgframework.p3.core.util.SystemTools;
import org.jeecgframework.p3.core.util.plugin.ViewVelocity;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.StringUtils;
import org.jeecgframework.p3.core.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeecg.p3.commonluckymoney.entity.WxActCommonluckymoneyRecord;
import com.jeecg.p3.commonluckymoney.exception.CommonluckymoneyException;
import com.jeecg.p3.commonluckymoney.exception.CommonluckymoneyExceptionEnum;
import com.jeecg.p3.commonluckymoney.service.WxActCommonluckymoneyRecordService;
import com.jeecg.p3.commonluckymoney.util.ExcelUtil;

 /**
 * 描述：</b>WxActCommonluckymoneyRecordController<br>拆红包参与记录表
 * @author huangqingquan
 * @since：2017年03月30日 11时44分52秒 星期四 
 * @version:1.0
 */
@Controller
@RequestMapping("/commonluckymoney/back/wxActCommonluckymoneyRecord")
public class WxActCommonluckymoneyRecordController extends BaseController{
  @Autowired
  private WxActCommonluckymoneyRecordService wxActCommonluckymoneyRecordService;
  
/**
  * 列表页面
  * @return
  */
@RequestMapping(value="list",method = {RequestMethod.GET,RequestMethod.POST})
public void list(@ModelAttribute WxActCommonluckymoneyRecord query,HttpServletResponse response,HttpServletRequest request,
			@RequestParam(required = false, value = "pageNo", defaultValue = "1") int pageNo,
			@RequestParam(required = false, value = "pageSize", defaultValue = "10") int pageSize) throws Exception{
		VelocityContext velocityContext = new VelocityContext();
		String viewName = "commonluckymoney/back/wxActCommonluckymoneyRecord-list.vm";
		try {
			if(StringUtils.isEmpty(query.getActId())){
	 			throw new CommonluckymoneyException(CommonluckymoneyExceptionEnum.ARGUMENT_ERROR);
		 	}
		 	PageQuery<WxActCommonluckymoneyRecord> pageQuery = new PageQuery<WxActCommonluckymoneyRecord>();
		 	pageQuery.setPageNo(pageNo);
		 	pageQuery.setPageSize(pageSize);
			pageQuery.setQuery(query);
			velocityContext.put("wxActCommonluckymoneyRecord",query);
			velocityContext.put("pageInfos",SystemTools.convertPaginatedList(wxActCommonluckymoneyRecordService.queryPageList(pageQuery)));
		} catch (Exception e) {
			e.printStackTrace();
		}
		ViewVelocity.view(request,response,viewName,velocityContext);
}

/**
 * 导出excel
 * @param request
 * @param response
 */
@RequestMapping(value="exportExcel",method = RequestMethod.GET)
@ResponseBody
public void exportExcel(HttpServletRequest request,HttpServletResponse response){
	try {
		String actId = request.getParameter("actId");
		List<WxActCommonluckymoneyRecord> wxActCommonluckymoneyRecordList = wxActCommonluckymoneyRecordService.queryListByActId(actId);
		ExcelUtil.exportExcel(request, response, wxActCommonluckymoneyRecordList, WxActCommonluckymoneyRecord.class, "拆红包中奖记录");
	} catch (Exception e) {
		e.printStackTrace();
	}
}
}

